﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Sudoku;
using MySql.Data.MySqlClient;

namespace DAL
{
    partial class DAL
    {
        public class SquareBoxDAO : IDaoCrud<SquareBox>
        {
            #region IDaoCrud<SquareBox> Members
            protected MySqlCommand c;
            public long create(SquareBox entity)
            {
                //Nepotrebno
                return new long();
            }

            public List<SquareBox> getAll()
            {
                //Nepotrebno
                return null;
            }

            public SquareBox read(SquareBox entity)
            {
                //Nepotrebno
                return null;
            }

            public SquareBox update(SquareBox entity)
            {
                //Nepotrebno
                return null;
            }

            public void delete(SquareBox entity)
            {
                //Nepotrebno
            }

            public SquareBox getById(int id)
            {
                try
                {
                    SquareBox t = new SquareBox();
                    int[] value = new int[9];

                    c = new MySqlCommand("select * from polje_a where tabla_id = @Id;", con);
                    c.Parameters.AddWithValue("@Id", id);
                    MySqlDataReader r = c.ExecuteReader();
                    if (r.Read())
                    {
                        value[0] = r.GetInt32("p1");
                        value[1] = r.GetInt32("p2");
                        value[2] = r.GetInt32("p3");
                        value[3] = r.GetInt32("p4");
                        value[4] = r.GetInt32("p5");
                        value[5] = r.GetInt32("p6");
                        value[6] = r.GetInt32("p7");
                        value[7] = r.GetInt32("p8");
                        value[8] = r.GetInt32("p9");
                        t.polje_a = value;
                        value = new int[9];
                    }
                    r.Close();
                    c.Dispose();

                    c = new MySqlCommand("select * from polje_b where tabla_id = @Id;", con);
                    c.Parameters.AddWithValue("@Id", id);
                    r = c.ExecuteReader();
                    if (r.Read())
                    {
                        value[0] = r.GetInt32("p1");
                        value[1] = r.GetInt32("p2");
                        value[2] = r.GetInt32("p3");
                        value[3] = r.GetInt32("p4");
                        value[4] = r.GetInt32("p5");
                        value[5] = r.GetInt32("p6");
                        value[6] = r.GetInt32("p7");
                        value[7] = r.GetInt32("p8");
                        value[8] = r.GetInt32("p9");
                        t.polje_b = value;
                        value = new int[9];
                    }
                    r.Close();
                    c.Dispose();

                    c = new MySqlCommand("select * from polje_c where tabla_id = @Id;", con);
                    c.Parameters.AddWithValue("@Id", id);
                    r = c.ExecuteReader();
                    if (r.Read())
                    {
                        value[0] = r.GetInt32("p1");
                        value[1] = r.GetInt32("p2");
                        value[2] = r.GetInt32("p3");
                        value[3] = r.GetInt32("p4");
                        value[4] = r.GetInt32("p5");
                        value[5] = r.GetInt32("p6");
                        value[6] = r.GetInt32("p7");
                        value[7] = r.GetInt32("p8");
                        value[8] = r.GetInt32("p9");
                        t.polje_c = value;
                        value = new int[9];
                    }
                    r.Close();
                    c.Dispose();

                    c = new MySqlCommand("select * from polje_d where tabla_id = @Id;", con);
                    c.Parameters.AddWithValue("@Id", id);
                    r = c.ExecuteReader();
                    if (r.Read())
                    {
                        value[0] = r.GetInt32("p1");
                        value[1] = r.GetInt32("p2");
                        value[2] = r.GetInt32("p3");
                        value[3] = r.GetInt32("p4");
                        value[4] = r.GetInt32("p5");
                        value[5] = r.GetInt32("p6");
                        value[6] = r.GetInt32("p7");
                        value[7] = r.GetInt32("p8");
                        value[8] = r.GetInt32("p9");
                        t.polje_d = value;
                        value = new int[9];
                    }
                    r.Close();
                    c.Dispose();

                    c = new MySqlCommand("select * from polje_e where tabla_id = @Id;", con);
                    c.Parameters.AddWithValue("@Id", id);
                    r = c.ExecuteReader();
                    if (r.Read())
                    {
                        value[0] = r.GetInt32("p1");
                        value[1] = r.GetInt32("p2");
                        value[2] = r.GetInt32("p3");
                        value[3] = r.GetInt32("p4");
                        value[4] = r.GetInt32("p5");
                        value[5] = r.GetInt32("p6");
                        value[6] = r.GetInt32("p7");
                        value[7] = r.GetInt32("p8");
                        value[8] = r.GetInt32("p9");
                        t.polje_e = value;
                        value = new int[9];
                    }
                    r.Close();
                    c.Dispose();

                    c = new MySqlCommand("select * from polje_f where tabla_id = @Id;", con);
                    c.Parameters.AddWithValue("@Id", id);
                    r = c.ExecuteReader();
                    if (r.Read())
                    {
                        value[0] = r.GetInt32("p1");
                        value[1] = r.GetInt32("p2");
                        value[2] = r.GetInt32("p3");
                        value[3] = r.GetInt32("p4");
                        value[4] = r.GetInt32("p5");
                        value[5] = r.GetInt32("p6");
                        value[6] = r.GetInt32("p7");
                        value[7] = r.GetInt32("p8");
                        value[8] = r.GetInt32("p9");
                        t.polje_f = value;
                        value = new int[9];
                    }
                    r.Close();
                    c.Dispose();

                    c = new MySqlCommand("select * from polje_g where tabla_id = @Id;", con);
                    c.Parameters.AddWithValue("@Id", id);
                    r = c.ExecuteReader();
                    if (r.Read())
                    {
                        value[0] = r.GetInt32("p1");
                        value[1] = r.GetInt32("p2");
                        value[2] = r.GetInt32("p3");
                        value[3] = r.GetInt32("p4");
                        value[4] = r.GetInt32("p5");
                        value[5] = r.GetInt32("p6");
                        value[6] = r.GetInt32("p7");
                        value[7] = r.GetInt32("p8");
                        value[8] = r.GetInt32("p9");
                        t.polje_g = value;
                        value = new int[9];
                    }
                    r.Close();
                    c.Dispose();

                    c = new MySqlCommand("select * from polje_h where tabla_id = @Id;", con);
                    c.Parameters.AddWithValue("@Id", id);
                    r = c.ExecuteReader();
                    if (r.Read())
                    {
                        value[0] = r.GetInt32("p1");
                        value[1] = r.GetInt32("p2");
                        value[2] = r.GetInt32("p3");
                        value[3] = r.GetInt32("p4");
                        value[4] = r.GetInt32("p5");
                        value[5] = r.GetInt32("p6");
                        value[6] = r.GetInt32("p7");
                        value[7] = r.GetInt32("p8");
                        value[8] = r.GetInt32("p9");
                        t.polje_h = value;
                        value = new int[9];
                    }
                    r.Close();
                    c.Dispose();


                    c = new MySqlCommand("select * from polje_i where tabla_id = @Id;", con);
                    c.Parameters.AddWithValue("@Id", id);
                    r = c.ExecuteReader();
                    if (r.Read())
                    {
                        value[0] = r.GetInt32("p1");
                        value[1] = r.GetInt32("p2");
                        value[2] = r.GetInt32("p3");
                        value[3] = r.GetInt32("p4");
                        value[4] = r.GetInt32("p5");
                        value[5] = r.GetInt32("p6");
                        value[6] = r.GetInt32("p7");
                        value[7] = r.GetInt32("p8");
                        value[8] = r.GetInt32("p9");
                        t.polje_i = value;
                        value = new int[9];
                    }
                    r.Close();
                    c.Dispose();

                    return t;
                }
                catch(Exception ex)
                {
                    throw ex;
                }
            }

            public List<SquareBox> getByExample(string name, string value)
            {
                //Nepotrebno
                return null;
            }
            #endregion
        }
    }
}
